<template>
  <div class="app-container">
    <!-- 查询 -->
    <tl-list-search ref="search" :query-param="queryParam" @search="doQuery" :isDisplayDefaultSearch="false" :isDisplaySearch="false" v-if="isHeaderDisplay">
      <template slot="search">
        <!-- <el-form-item prop="code" v-if="editFlag">
          <label>项目</label>
          <el-input v-model="queryParam.qry_projectname" :disabled="true" class="tl-ref-selector" style="width:200px">
            <el-button slot="append" type="primary" icon="el-icon-search" @click="openPmProjectRefDialog"></el-button>
          </el-input>
        </el-form-item> -->
        <!-- <el-form-item label="项目名称">
          <el-input v-model="queryParam.qry_projectName"></el-input>
        </el-form-item>
        <el-form-item label="项目编号">
          <el-input v-model="queryParam.qry_projectCode" style="width:110px"></el-input>
        </el-form-item>
        <el-form-item label="项目经理">
          <el-input v-model="queryParam.qry_projectManager" placeholder="姓名/工号" style="width:100px"></el-input>
        </el-form-item> -->
        <el-form-item prop="code" label="姓名">
          <el-input v-model="queryParam.qry_name" placeholder="成员姓名" @change="changeName"></el-input>
        </el-form-item>
        <el-form-item label="工号">
          <el-input v-model="queryParam.qry_code" placeholder="成员工号" @change="changeCode"></el-input>
        </el-form-item>
        <el-form-item label="项目角色">
          <el-select v-model="queryParam.qry_role" clearable>
            <el-option v-for="item in codeModel.roleList" :key="item.code" :label="item.name" :value="item.code" clearable @chang="changeRole" />
          </el-select>
        </el-form-item>
        <el-button class="filter-item" type="primary" icon="el-icon-search" @click="doQuery">搜索</el-button>
        <el-button class="filter-item" type="primary" icon="el-icon-refresh-right" @click="resetQueryParam" v-if="editFlag" :disabled="isreset">重置</el-button>
      </template>
    </tl-list-search>
    <!-- 工具栏 -->
    <tl-list-toolbar ref="toolbar" v-if="editFlag" @add="openAddDialog('editForm')" :isDisplayExport="false" @exportExcel="doExportExcel" :isDisplayDeleteBatch="false" @deleteBatch="doDeleteBatch" @refresh="doRefresh" @columnCustomize="doColumnCustomize" @displaySearch="doDisplaySearch" :disableDeleteBatch="selectedRowKeys.length <= 0">
      <template slot="left-btn"> </template>
    </tl-list-toolbar>
    <div>
      <!-- 列表选择 -->
      <div class="table-alert-div" ref="selector">
        <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
          <template slot="title">
            已选择&nbsp;<a class="tl-table-alert-info-a1">{{ selectedRowKeys.length }}</a>项&nbsp;&nbsp;
            <a class="tl-table-alert-info-a2" @click="doClearSelected">全部清空</a>
          </template>
        </el-alert>
      </div>
      <!--表格渲染-->
      <el-table class="tl-table" ref="mainTable" :height="tableHeight" resizable-key="tableHeight" :resizable-refs="tableResizeRefs" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" row-key="id" border fit :row-class-name="doChangeRowClassName">
        <!-- <el-table-column type="selection" width="55px" fixed="left"></el-table-column> -->
        <el-table-column type="index" label="序号" width="55px" align="center"></el-table-column>
        <el-table-column prop="username" label="姓名" width="80px" sortable="custom" sort-by="username" align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="usercode" label="工号" width="80px" sortable="custom" sort-by="usercode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="disprole" label="项目角色" width="100px" sortable="custom" sort-by="role" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="enabled" label="有效" width="100px" sortable="custom" sort-by="enabled" align="center" header-align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.enabled === 1" type="success">是</el-tag>
            <el-tag v-else type="danger">否</el-tag>
          </template>
        </el-table-column>
        <el-table-column v-if="editFlag" prop="dispprojectid" label="所属项目" width="300px" sortable="custom" sort-by="projectid" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="orgname" label="所属公司" width="200px" sortable="custom" sort-by="orgname" align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="orgcode" label="公司编码" width="100px" sortable="custom" sort-by="orgcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="deptname" label="所属部门" width="200px" sortable="custom" sort-by="deptname" align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="deptcode" label="部门编码" width="100px" sortable="custom" sort-by="deptcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="duty" label="职责" width="200px" sortable="custom" sort-by="duty" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="phone" label="联系电话" width="120px" sortable="custom" sort-by="phone" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="leader" label="上级领导" width="100px" sortable="custom" sort-by="leader" align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="leadercode" label="上级领导工号" width="120px" sortable="custom" sort-by="leadercode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispfrequency" label="参与频度" width="100px" sortable="custom" sort-by="frequency" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="description" label="备注" min-width="250px" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column label="操作" width="100px" v-slot="scope" fixed="right">
          <el-dropdown trigger="hover">
            <el-button type="text" icon="el-icon-s-operation" style="margin-left:10px">操作<i class="el-icon-arrow-down el-icon--right"></i></el-button>
            <el-dropdown-menu>
              <el-dropdown-item icon="el-icon-view" @click.native="openViewDialog('editForm', scope.row.id)">查看</el-dropdown-item>
              <el-dropdown-item icon="el-icon-edit" @click.native="openEditDialog('editForm', scope.row.id)" :disabled="!editFlag">编辑</el-dropdown-item>
              <!-- <el-dropdown-item icon="el-icon-copy-document" @click.native="doCopy(scope.row)" :disabled="!editFlag">复制</el-dropdown-item> -->
              <el-dropdown-item icon="el-icon-delete" @click.native="doDelete(scope.row.id)" :disabled="!editFlag">删除</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-table-column>
      </el-table>
      <!-- 列表分页 -->
      <el-row class="pagebar" ref="pager">
        <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
      </el-row>
      <tl-edit ref="editForm" @refresh="doRefresh" :projectId="projectId" :editFlag="editFlag"></tl-edit>
      <tl-pm-project-ref ref="pmProjectRef" @confirm="getPmProjectRefData" :isSingleSelect="true"></tl-pm-project-ref>
    </div>
  </div>
</template>

<script>
/** mixins */
import { mixin_list } from '@tapui/mixins/mixin_list'
/** 子组件 */
import tlEdit from './edit'
import tlPmProjectRef from '@/views/ProjectManage/pmProject/refList'
/** 工具类 */
import { getAction, putAction, postAction, deleteAction } from '@tapui/utils/http'
export default {
  name: 'pmTeam',
  mixins: [mixin_list],
  components: { tlEdit, tlPmProjectRef },
  data() {
    return {
      description: '项目组成员-列表查询',
      urlPrefix: '/pm/team/',
      url: {
        queryCodeList: '/pm/team/dataCodeList'
      },
      // 排序参数
      sorterInfo: {
        sidx: 'createon',
        sord: 'desc'
      },
      queryParam: {
        qry_projectid: this.projectId
      },
      // 当前页面的编辑状态
      editFlag: true,
      reduceHeight: 325,
      isreset: false
    }
  },
  props: {
    projectId: {
      type: [Number, String],
      default: function() {
        return ''
      }
    },
    // 模块是否可以编辑
    moduleEditFlag: {
      type: Number,
      default: function() {
        return 1
      }
    },
    // 当前登录人角色 PM--项目经理 PP--项目参数人 OTHER--其他
    currentRole: {
      type: String,
      default: function() {
        return 'PM'
      }
    }
  },
  methods: {
    changeName() {
      if (JSON.stringify(this.queryParam) !== '{}' && this.queryParam.qry_name !== '') {
        this.isreset = false
      } else {
        this.isreset = true
      }
    },
    changeCode() {
      if (JSON.stringify(this.queryParam) !== '{}' && this.queryParam.qry_code !== '') {
        this.isreset = false
      } else {
        this.isreset = true
      }
    },
    changeRole() {
      if (JSON.stringify(this.queryParam) !== '{}' && this.queryParam.qry_role !== '') {
        this.isreset = false
      } else {
        this.isreset = true
      }
    },
    afterLoadData() {
      this.isreset = false
      if (typeof this.queryParam.qry_name === 'undefined' &&
        typeof this.queryParam.qry_code === 'undefined' &&
        typeof this.queryParam.qry_role === 'undefined') {
        this.isreset = true
      }
    },
    /** 打开项目参照 */
    openPmProjectRefDialog() {
      this.$refs.pmProjectRef.visible = true
    },
    /** 获取项目参数数据 */
    getPmProjectRefData(selectionRow, selectKey, selectionValue) {
      const { id, name } = selectionRow
      this.$set(this.queryParam, 'qry_projectid', id)
      this.$set(this.queryParam, 'qry_projectname', name)
    },
    resetQueryParam() {
      this.queryParam = {}
      this.changeName()
      this.changeCode()
      this.changeRole()
    },
    /** 表格双击事件 */
    doRowDbClick(row, column, event) {
      // this.openViewDialog('editForm', row.id)
      if (this.rowDbClickActionType === 'edit' && this.editFlag) {
        this.openEditDialog('editForm', row.id)
      } else {
        this.openViewDialog('editForm', row.id)
      }
    },
    initParam() {
      this.editFlag = this.moduleEditFlag === 1 && this.currentRole === 'PM'
      this.reduceHeight = this.editFlag ? 134 : 325
    },
    searchList(projectId) {
      if (!this.editFlag) {
        this.queryParam.qry_projectid = projectId
        this.loadData({})
      }
    },
    doCopy(obj) {
      // 打开对话框
      this.openAddDialog('editForm')
      this.$nextTick(() => {
        this.$refs.editForm.copyObj(obj)
      })
    }
  },
  watch: {
    projectId(newValue, oldValue) {
      this.searchList(newValue)
    }
  },
  mounted() {
    this.initParam()
  }
}
</script>

<style scoped></style>

